package com.umakr.ax.common.service;

import com.umakr.ax.common.mapper.MsgMapper;
import com.umakr.ax.common.model.Msg;
import com.umakr.ax.common.model.SeekHelpInfo;
import com.umakr.ax.core.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 消息 服务实现类
 * </p>
 *
 * @author Umakr-Code-Generator
 * @since 2017-12-30
 */
@Service
public class MsgService extends BaseService<MsgMapper, Msg>{

    @Autowired
    SeekHelpInfoService seekHelpInfoService;

    public Object delMsg(Long id) {
        Msg targetMsg = queryById(id);
        baseMapper.delMsg(id);
        //删除对应的Msg，如果help_id不为null则必须把求助信息也软删除
        if(targetMsg != null && targetMsg.getHelpId() != null){
            SeekHelpInfo seekHelpInfo = seekHelpInfoService.queryById(targetMsg.getHelpId());
            if(seekHelpInfo != null && seekHelpInfo.getDelStatus() == 0){
                seekHelpInfoService.delSeekHelpInfo(targetMsg.getHelpId(),1);
            }
        }
        return true;
    }

    public boolean insertForWechat(String msgAttachmentAddr, String msgTxtContent, Date msgTime, Integer msgContentType, Integer radioLen, String positionCoor, String positionName, Long rsId, Long userId, String wechatIdData, String wechatMsgData, String wechatUserData, Integer msgType, Integer msgDirect, Integer status, Integer messageFrom) {
        return baseMapper.insertForWechat(msgAttachmentAddr, msgTxtContent, msgTime, msgContentType, radioLen, positionCoor, positionName, rsId, userId, wechatIdData, wechatMsgData, wechatUserData, msgType, msgDirect, status, messageFrom);
    }

}
